<?php

function voteProductHandler() {
    var_dump($_POST);
}
add_action( 'wp_ajax_voteProduct', 'voteProductHandler' );

function voteProduct($pid)
{
        ?>
        <script>
        var selector ='<?php echo "#".$idname; ?>';
        var pid ='<?php echo $pid; ?>';
        var upOrDown = '<?php echo $upOrDown; ?>';
        var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
        jQuery(document).ready(function () {
            jQuery("#product_vote_up").click(function(e){
                actionAjax('up');
            }); 
            jQuery("#product_vote_down").click(function(e){
                actionAjax('down');
            }); 
        });
        
        function actionAjax(upOrDown){
                jQuery.post(
                ajaxurl, 
                {
                    'action': 'voteProduct',
                    'pid': pid,
                    'upordown': upOrDown
                }, 
                function(response){
                    alert('The server responded: ' + response);
                }
                );
            
         }  
        </script>        
        <a id="product_vote_up">Up</a>
        <a id="product_vote_down">Down</a>
        
    <?php
}


?>
